set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)

cmake_minimum_required(VERSION 3.22)

project(asan_test)

aux_source_directory(. CPP_FILES)

# 添加编译参数，打开asan编译开关
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize-recover=all -fno-omit-frame-pointer -g")

add_executable(asan_test ${CPP_FILES})

# 找到asan库文件并进行链接
find_library(LIB_ASAN NAME libasan.so PATHS /lib/gcc/x86_64-linux-gnu/11/)
message(STATUS "### ${LIB_ASAN} ###")
target_link_libraries(asan_test ${LIB_ASAN})